package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import org.springframework.context.ApplicationContext;
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.ArrayList; 
import java.util.List; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblThongTinHocVienDTB;
import com.lb.jwitter.service.TblThongTinHocVienDTBService;
import com.lb.jwitter.service.TblThongTinHocVien;
import com.lb.jwitter.service.TblThongTinHocVienService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblThongTinHocVientblThongTinHocVienDTBInsertAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private Long id; 
    public void setId(Long id) {
       this.id = id;
 }

    private int hocVienId; 
    public void setHocVienId(int hocVienId) {
       this.hocVienId = hocVienId;
 }

    public int getHocVienId() {
       return hocVienId;
 }

    private TblThongTinHocVienService tblThongTinHocVienService; 

    private String maHocKy; 
    public void setMaHocKy(String maHocKy) {
       this.maHocKy = maHocKy;
 }

    public String getMaHocKy() {
       return maHocKy;
 }

    private double diem; 
    public void setDiem(double diem) {
       this.diem = diem;
 }

    public double getDiem() {
       return diem;
 }

    private double dTBTichLuy; 
    public void setDTBTichLuy(double dTBTichLuy) {
       this.dTBTichLuy = dTBTichLuy;
 }

    public double getDTBTichLuy() {
       return dTBTichLuy;
 }

    private double dTBTichLuyNganh; 
    public void setDTBTichLuyNganh(double dTBTichLuyNganh) {
       this.dTBTichLuyNganh = dTBTichLuyNganh;
 }

    public double getDTBTichLuyNganh() {
       return dTBTichLuyNganh;
 }

    private double tCTL; 
    public void setTCTL(double tCTL) {
       this.tCTL = tCTL;
 }

    public double getTCTL() {
       return tCTL;
 }

    private double tCTLNganh; 
    public void setTCTLNganh(double tCTLNganh) {
       this.tCTLNganh = tCTLNganh;
 }

    public double getTCTLNganh() {
       return tCTLNganh;
 }

    private TblThongTinHocVienDTB tblThongTinHocVienDTB; 
    public TblThongTinHocVienDTB  getTblThongTinHocVienDTB() {
        return tblThongTinHocVienDTB;
 }

    private List<TblThongTinHocVienDTB> tblThongTinHocVienDTBs; 
    public List<TblThongTinHocVienDTB>  getTblThongTinHocVienDTBs() {
        return tblThongTinHocVienDTBs; 
      } 

    private TblThongTinHocVienDTBService tblThongTinHocVienDTBService; 

	private int preInsert(Message msg, TblThongTinHocVienDTB obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postInsert(Message msg, TblThongTinHocVienDTB obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_ThongTin_HocVien_DTB", "them")){ 
        return "noprivilege"; 
    }
        tblThongTinHocVienDTBService = (TblThongTinHocVienDTBService) context.getBean("tbl_ThongTin_HocVien_DTBClient"); 
        tblThongTinHocVienService = (TblThongTinHocVienService) context.getBean("tbl_ThongTin_HocVienClient"); 

        msg = new Message(); 
        tblThongTinHocVienDTB = new TblThongTinHocVienDTB(); 
        tblThongTinHocVienDTB.setHocVienId(tblThongTinHocVienService.gettblThongTinHocVien(new Long(hocVienId))); 
        tblThongTinHocVienDTB.setMaHocKy(maHocKy); 
        tblThongTinHocVienDTB.setDiem(diem); 
        tblThongTinHocVienDTB.setDTBTichLuy(dTBTichLuy); 
        tblThongTinHocVienDTB.setDTBTichLuyNganh(dTBTichLuyNganh); 
        tblThongTinHocVienDTB.setTCTL(tCTL); 
        tblThongTinHocVienDTB.setTCTLNganh(tCTLNganh); 
        preInsert(msg,tblThongTinHocVienDTB); 
       if (msg.isPreMessage_b()) 
       { 
           tblThongTinHocVienDTBService.createtblThongTinHocVienDTB(tblThongTinHocVienDTB); 
           postInsert(msg, tblThongTinHocVienDTB); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 
       if(pageSize == 0){ 
           pageSize = 20; 
       } 
        if(page == 0){ 
           page =1; 
       } 
        List < ConditionReport > cons = new ArrayList<ConditionReport>(); 
        ConditionReport con = new ConditionReport(); 
        con.setCol("hocVienId.id"); 
        con.setValue1(new Long(hocVienId)); 
        con.setOperator("eq"); 
        cons.add(con); 
      tblThongTinHocVienDTBs =       tblThongTinHocVienDTBService.findtblThongTinHocVienDTBByCondition(cons,pageSize, page); 
      pages = tblThongTinHocVienDTBService.counttblThongTinHocVienDTBByCondition(cons)/pageSize + 1; 
      dataString = ""; 
      dataString += "&id="; 
      dataString += "&hocVienId="; 
      dataString += "&maHocKy="; 
      dataString += "&diem="; 
      dataString += "&dTBTichLuy="; 
      dataString += "&dTBTichLuyNganh="; 
      dataString += "&tCTL="; 
      dataString += "&tCTLNganh="; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Insert tbl_ThongTin_HocVien_DTB Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
